package com.cac.demo.newCode.sorting.service.Impl;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cac.demo.util.adapter.ResponseMsg;
import com.cac.demo.newCode.sorting.dto.SortingDemoDTO;
import com.cac.demo.newCode.sorting.entity.SortingDemo;
import com.cac.demo.newCode.sorting.enums.SortingDemoEnum;
import com.cac.demo.newCode.sorting.mapper.SortingDemoMapper;
import com.cac.demo.newCode.sorting.service.ISortingDemoService;
import com.cac.demo.newCode.sorting.vo.SortingDemoVO;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class
SortingDemoServiceImpl extends ServiceImpl<SortingDemoMapper, SortingDemo> implements ISortingDemoService {
    @Resource
    private SortingDemoMapper sortingDemoMapper;
    @Override
    public ResponseMsg<Object> sortingDemoTest(SortingDemoDTO sortingDemoDTO) {
        //业务处理

        //DTO转Entity随后执行单表操作基本用于单表修改或者批量修改
        SortingDemo sortingDemo = new SortingDemo();
        BeanUtils.copyProperties(sortingDemoDTO,sortingDemo);


        //枚举的使用
        sortingDemo.setGender(SortingDemoEnum.MAN.getCode());

        //使用修改
        this.updateById(sortingDemo);



        //如果是需要单表数据就直接返回
        List<SortingDemo> list = this.list();
        ResponseMsg responseMsg = new ResponseMsg();
        responseMsg.setResponseBody(list);


        //如果是连表查询则用VO接收然后返回
        SortingDemoVO sortingDemoVO = sortingDemoMapper.selectCarAndInvInBillH(sortingDemoDTO);
        responseMsg.setResponseBody(sortingDemoVO);
        return responseMsg;
    }
}
